using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.EntityFrameworkCore;
using CKY.AgentPlatform.Mcp;

namespace CKY.AgentPlatform.EntityFrameworkCore
{
    public static class EntityFrameworkCoreMcpConfiguration
    {
        public static void ConfigureMcp(this ModelBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));

            /* Configure all entities here. Example:

            builder.Entity<YourEntity>(b =>
            {
                // Configure table name and schema.
                b.ToTable(AbpAuditLoggingDbProperties.DbTablePrefix + "YourEntities", AbpAuditLoggingDbProperties.DbSchema);

                // Configure primary key.
                b.HasKey(x => x.Id);

                // Configure other properties.
                b.Property(x => x.Name).IsRequired().HasMaxLength(YourEntityConsts.MaxNameLength);

                // Configure relations.
                b.HasOne(x => x.YourOtherEntity).WithMany().HasForeignKey(x => x.YourOtherEntityId);
            });
            */

            builder.Entity<CKY.AgentPlatform.Mcp.McpServer>(b =>
            {
                b.ToTable(AgentPlatformConsts.DbTablePrefix + "McpServers", AgentPlatformConsts.DbSchema);

                b.ConfigureByConvention();

                b.Property(x => x.Name).IsRequired().HasMaxLength(128);
                b.Property(x => x.Description).HasMaxLength(500);
                b.Property(x => x.ServerType).HasMaxLength(64);
                b.Property(x => x.Host).IsRequired().HasMaxLength(256);
                b.Property(x => x.Port).IsRequired();
                b.Property(x => x.Status).IsRequired().HasMaxLength(32);
                b.Property(x => x.IsActive).IsRequired();
                b.Property(x => x.ToolCount).IsRequired();
                b.Property(x => x.ResourceCount).IsRequired();

                b.HasIndex(x => x.Name);
                b.HasIndex(x => x.Host);
                b.HasIndex(x => x.Status);
                b.HasIndex(x => x.IsActive);
            });
        }
    }
}